<?php
/**
 * Created by PhpStorm.
 * User: MIS
 * Date: 2018/10/29
 * Time: 10:29
 */
namespace Admin\Controller;
use Think\Controller;
class EditBlankController extends Controller
{
    public function index()
    {
        $id=I("id");
        $tid=session("tid");
//     var_dump($id);
//        var_dump($tid);
//     exit();
        if($id){
            $blank = M('tk');
            $this->tk_litem=$blank->where('`id`='.$id)->find();
//            echo $blank->getLastSql();
//            var_dump($this->tk_litem);
//            var_dump($this->tk_litem["content"]);
//            exit();
            $this->assign('tk_litem',$this->tk_litem);
            $this->assign('tk_content',$this->tk_litem["content"]);
            $this->assign('tk_success',$this->tk_litem["success"]);
            $this->assign('tk_id',$this->tk_litem["id"]);
            $this->assign('tk_litem',"updata");
        }else{
            $this->assign('tk_litem',"add");
        }
        $this->display();
    }
    public function  add(){
//        var_dump("1111111111");
//        exit();
        $blank = M('tk');
        $data=array(
            "content"=>I("content"),
            "success"=>I("success"),
            "tid"=>session("tid")
        );
            if($blank->add($data)){
                $this->success('填空题添加成功',U('/Admin/Blank/index',array('id'=>$_SESSION["id"])));
            }else{
                $this->error('填空题添加失败');
            }

    }

    public  function  updata(){
        $blank = M('tk');
        $data=array(
            "content"=>I("content"),
            "success"=>I('success'),
        );
        $id=I('id');
     $flag=$blank->where('`id`='.$id)->setField($data);
//        echo $blank->getLastSql();
//                   exit();
        if($flag){
            $this->success('填空题修改成功',U('/Admin/Blank/index',array('id'=>$_SESSION["id"])));
        }else{
            $this->error('填空题修改失败');
        }
    }




}